﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

namespace Zhongy
{
    public class UserHandler : IHandler
    {
        private UserCache userCache = Cache.User;

        public override void OnDisconnect(ClientPer client)
        {
            if (userCache.IsExsitClient(client))
                userCache.OfflineUser(client);
        }

        public override void OnReceive(ClientPer client, SocketReceiveMsg msg)
        {
            switch (msg.MT)
            {
                case OpCode.TYPE_SYN_STU_STATUS:
                    SyncUserInfo(client, msg);
                    break;

                default:
                    Debug.LogError("信息归属不对");
                    break;
            }
        }

        private void SyncUserInfo(ClientPer client, SocketReceiveMsg msg)
        {
            SingleExecute.Instance.Execute(() =>
            {
                if (msg.player != null && msg.player.Count > 0)
                {
                    userCache.SysncOnlineUsersState(client, msg.player);
                }
            });
        }
    }
}
